# -*- coding: utf-8 -*-

import sip
sip.setapi('QString', 2)
sip.setapi('QStringList', 2)
sip.setapi('QVariant', 2)

from PyQt4 import QtCore

#_______________________________________________________________________________
class TimerThread(QtCore.QThread):
    def __init__(self, fun, singleshot=False):
        QtCore.QThread.__init__(self)
        self.timer = QtCore.QTimer()
        if singleshot:
            self.timer.setSingleShot(True)
        self.timer.timeout.connect(fun, type=QtCore.Qt.DirectConnection) 
        
    def run(self):
        self.timer.start(500)
        self.exec_()    
    
    def exit_(self):
        self.timer.stop()
        self.exit()
        self.wait()
